﻿using System;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.Web;
using System.Collections.Generic;
using DevExpress.ExpressApp.Xpo;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Security.ClientServer;

namespace AturableWira.Web {
    // For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/DevExpressExpressAppWebWebApplicationMembersTopicAll.aspx
    public partial class AturableWiraAspNetApplication : WebApplication {
        private DevExpress.ExpressApp.SystemModule.SystemModule module1;
        private DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule module2;
        private AturableWira.Module.AturableWiraModule module3;
        private AturableWira.Module.Web.AturableWiraAspNetModule module4;
        private DevExpress.ExpressApp.Security.SecurityModule securityModule1;
        private DevExpress.ExpressApp.Security.SecurityStrategyComplex securityStrategyComplex1;
        private DevExpress.ExpressApp.Security.AuthenticationStandard authenticationStandard1;
        private DevExpress.ExpressApp.AuditTrail.AuditTrailModule auditTrailModule;
        private DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule objectsModule;
        private DevExpress.ExpressApp.Chart.ChartModule chartModule;
        private DevExpress.ExpressApp.Chart.Web.ChartAspNetModule chartAspNetModule;
        private DevExpress.ExpressApp.CloneObject.CloneObjectModule cloneObjectModule;
        private DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule conditionalAppearanceModule;
        private DevExpress.ExpressApp.Dashboards.DashboardsModule dashboardsModule;
        private DevExpress.ExpressApp.Dashboards.Web.DashboardsAspNetModule dashboardsAspNetModule;
        private DevExpress.ExpressApp.FileAttachments.Web.FileAttachmentsAspNetModule fileAttachmentsAspNetModule;
        private DevExpress.ExpressApp.HtmlPropertyEditor.Web.HtmlPropertyEditorAspNetModule htmlPropertyEditorAspNetModule;
        private DevExpress.ExpressApp.Kpi.KpiModule kpiModule;
        private DevExpress.ExpressApp.Maps.Web.MapsAspNetModule mapsAspNetModule;
        private DevExpress.ExpressApp.Notifications.NotificationsModule notificationsModule;
        private DevExpress.ExpressApp.Notifications.Web.NotificationsAspNetModule notificationsAspNetModule;
        private DevExpress.ExpressApp.PivotChart.PivotChartModuleBase pivotChartModuleBase;
        private DevExpress.ExpressApp.PivotChart.Web.PivotChartAspNetModule pivotChartAspNetModule;
        private DevExpress.ExpressApp.PivotGrid.PivotGridModule pivotGridModule;
        private DevExpress.ExpressApp.PivotGrid.Web.PivotGridAspNetModule pivotGridAspNetModule;
        private DevExpress.ExpressApp.ReportsV2.ReportsModuleV2 reportsModuleV2;
        private DevExpress.ExpressApp.ReportsV2.Web.ReportsAspNetModuleV2 reportsAspNetModuleV2;
        private DevExpress.ExpressApp.Scheduler.SchedulerModuleBase schedulerModuleBase;
        private DevExpress.ExpressApp.Scheduler.Web.SchedulerAspNetModule schedulerAspNetModule;
        private DevExpress.ExpressApp.ScriptRecorder.ScriptRecorderModuleBase scriptRecorderModuleBase;
        private DevExpress.ExpressApp.ScriptRecorder.Web.ScriptRecorderAspNetModule scriptRecorderAspNetModule;
        private DevExpress.ExpressApp.StateMachine.StateMachineModule stateMachineModule;
        private DevExpress.ExpressApp.TreeListEditors.TreeListEditorsModuleBase treeListEditorsModuleBase;
        private DevExpress.ExpressApp.TreeListEditors.Web.TreeListEditorsAspNetModule treeListEditorsAspNetModule;
        private DevExpress.ExpressApp.Validation.ValidationModule validationModule;
        private DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule validationAspNetModule;
        private DevExpress.ExpressApp.ViewVariantsModule.ViewVariantsModule viewVariantsModule;
        private DevExpress.ExpressApp.Workflow.WorkflowModule workflowModule;

        public AturableWiraAspNetApplication() {
            InitializeComponent();
            LinkNewObjectToParentImmediately = false;
            DevExpress.ExpressApp.Web.Editors.ASPx.ASPxGridListEditor.AllowFilterControlHierarchy = true;
            DevExpress.ExpressApp.Web.Editors.ASPx.ASPxGridListEditor.MaxFilterControlHierarchyDepth = 3;
            DevExpress.ExpressApp.Web.Editors.ASPx.ASPxCriteriaPropertyEditor.AllowFilterControlHierarchyDefault = true;
            DevExpress.ExpressApp.Web.Editors.ASPx.ASPxCriteriaPropertyEditor.MaxHierarchyDepthDefault = 3;
        }
        protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
            args.ObjectSpaceProvider = new SecuredObjectSpaceProvider((SecurityStrategyComplex)Security, GetDataStoreProvider(args.ConnectionString, args.Connection), true);
            args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
        }
        private IXpoDataStoreProvider GetDataStoreProvider(string connectionString, System.Data.IDbConnection connection) {
            System.Web.HttpApplicationState application = (System.Web.HttpContext.Current != null) ? System.Web.HttpContext.Current.Application : null;
            IXpoDataStoreProvider dataStoreProvider = null;
            if(application != null && application["DataStoreProvider"] != null) {
                dataStoreProvider = application["DataStoreProvider"] as IXpoDataStoreProvider;
            }
            else {
                if(!String.IsNullOrEmpty(connectionString)) {
                    connectionString = DevExpress.Xpo.XpoDefault.GetConnectionPoolString(connectionString);
                    dataStoreProvider = new ConnectionStringDataStoreProvider(connectionString, true);
                }
                else if(connection != null) {
                    dataStoreProvider = new ConnectionDataStoreProvider(connection);
                }
                if(application != null) {
                    application["DataStoreProvider"] = dataStoreProvider;
                }
            }
			return dataStoreProvider;
        }
        private void AturableWiraAspNetApplication_DatabaseVersionMismatch(object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) {
#if EASYTEST
            e.Updater.Update();
            e.Handled = true;
#else
            if(System.Diagnostics.Debugger.IsAttached) {
                e.Updater.Update();
                e.Handled = true;
            }
            else {
				string message = "The application cannot connect to the specified database, " +
					"because the database doesn't exist, its version is older " +
					"than that of the application or its schema does not match " +
					"the ORM data model structure. To avoid this error, use one " +
					"of the solutions from the https://www.devexpress.com/kb=T367835 KB Article.";

                if(e.CompatibilityError != null && e.CompatibilityError.Exception != null) {
                    message += "\r\n\r\nInner exception: " + e.CompatibilityError.Exception.Message;
                }
                throw new InvalidOperationException(message);
            }
#endif
        }
        private void InitializeComponent() {
      this.module1 = new DevExpress.ExpressApp.SystemModule.SystemModule();
      this.module2 = new DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule();
      this.module3 = new AturableWira.Module.AturableWiraModule();
      this.module4 = new AturableWira.Module.Web.AturableWiraAspNetModule();
      this.securityModule1 = new DevExpress.ExpressApp.Security.SecurityModule();
      this.securityStrategyComplex1 = new DevExpress.ExpressApp.Security.SecurityStrategyComplex();
      this.authenticationStandard1 = new DevExpress.ExpressApp.Security.AuthenticationStandard();
      this.auditTrailModule = new DevExpress.ExpressApp.AuditTrail.AuditTrailModule();
      this.objectsModule = new DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule();
      this.chartModule = new DevExpress.ExpressApp.Chart.ChartModule();
      this.chartAspNetModule = new DevExpress.ExpressApp.Chart.Web.ChartAspNetModule();
      this.cloneObjectModule = new DevExpress.ExpressApp.CloneObject.CloneObjectModule();
      this.conditionalAppearanceModule = new DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule();
      this.dashboardsModule = new DevExpress.ExpressApp.Dashboards.DashboardsModule();
      this.dashboardsAspNetModule = new DevExpress.ExpressApp.Dashboards.Web.DashboardsAspNetModule();
      this.fileAttachmentsAspNetModule = new DevExpress.ExpressApp.FileAttachments.Web.FileAttachmentsAspNetModule();
      this.htmlPropertyEditorAspNetModule = new DevExpress.ExpressApp.HtmlPropertyEditor.Web.HtmlPropertyEditorAspNetModule();
      this.kpiModule = new DevExpress.ExpressApp.Kpi.KpiModule();
      this.mapsAspNetModule = new DevExpress.ExpressApp.Maps.Web.MapsAspNetModule();
      this.notificationsModule = new DevExpress.ExpressApp.Notifications.NotificationsModule();
      this.notificationsAspNetModule = new DevExpress.ExpressApp.Notifications.Web.NotificationsAspNetModule();
      this.pivotChartModuleBase = new DevExpress.ExpressApp.PivotChart.PivotChartModuleBase();
      this.pivotChartAspNetModule = new DevExpress.ExpressApp.PivotChart.Web.PivotChartAspNetModule();
      this.pivotGridModule = new DevExpress.ExpressApp.PivotGrid.PivotGridModule();
      this.pivotGridAspNetModule = new DevExpress.ExpressApp.PivotGrid.Web.PivotGridAspNetModule();
      this.reportsModuleV2 = new DevExpress.ExpressApp.ReportsV2.ReportsModuleV2();
      this.reportsAspNetModuleV2 = new DevExpress.ExpressApp.ReportsV2.Web.ReportsAspNetModuleV2();
      this.schedulerModuleBase = new DevExpress.ExpressApp.Scheduler.SchedulerModuleBase();
      this.schedulerAspNetModule = new DevExpress.ExpressApp.Scheduler.Web.SchedulerAspNetModule();
      this.scriptRecorderModuleBase = new DevExpress.ExpressApp.ScriptRecorder.ScriptRecorderModuleBase();
      this.scriptRecorderAspNetModule = new DevExpress.ExpressApp.ScriptRecorder.Web.ScriptRecorderAspNetModule();
      this.stateMachineModule = new DevExpress.ExpressApp.StateMachine.StateMachineModule();
      this.treeListEditorsModuleBase = new DevExpress.ExpressApp.TreeListEditors.TreeListEditorsModuleBase();
      this.treeListEditorsAspNetModule = new DevExpress.ExpressApp.TreeListEditors.Web.TreeListEditorsAspNetModule();
      this.validationModule = new DevExpress.ExpressApp.Validation.ValidationModule();
      this.validationAspNetModule = new DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule();
      this.viewVariantsModule = new DevExpress.ExpressApp.ViewVariantsModule.ViewVariantsModule();
      this.workflowModule = new DevExpress.ExpressApp.Workflow.WorkflowModule();
      ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
      // 
      // securityStrategyComplex1
      // 
      this.securityStrategyComplex1.Authentication = this.authenticationStandard1;
      this.securityStrategyComplex1.RoleType = typeof(AturableWira.Module.BusinessObjects.HRM.EmployeeRole);
      this.securityStrategyComplex1.SupportNavigationPermissionsForTypes = false;
      this.securityStrategyComplex1.UserType = typeof(AturableWira.Module.BusinessObjects.HRM.Employee);
      // 
      // authenticationStandard1
      // 
      this.authenticationStandard1.LogonParametersType = typeof(DevExpress.ExpressApp.Security.AuthenticationStandardLogonParameters);
      // 
      // auditTrailModule
      // 
      this.auditTrailModule.AuditDataItemPersistentType = typeof(DevExpress.Persistent.BaseImpl.AuditDataItemPersistent);
      // 
      // dashboardsModule
      // 
      this.dashboardsModule.DashboardDataType = typeof(DevExpress.Persistent.BaseImpl.DashboardData);
      // 
      // notificationsModule
      // 
      this.notificationsModule.CanAccessPostponedItems = false;
      this.notificationsModule.NotificationsRefreshInterval = System.TimeSpan.Parse("00:05:00");
      this.notificationsModule.NotificationsStartDelay = System.TimeSpan.Parse("00:00:05");
      this.notificationsModule.ShowDismissAllAction = false;
      this.notificationsModule.ShowNotificationsWindow = true;
      this.notificationsModule.ShowRefreshAction = false;
      // 
      // pivotChartModuleBase
      // 
      this.pivotChartModuleBase.DataAccessMode = DevExpress.ExpressApp.CollectionSourceDataAccessMode.Client;
      this.pivotChartModuleBase.ShowAdditionalNavigation = false;
      // 
      // reportsModuleV2
      // 
      this.reportsModuleV2.EnableInplaceReports = true;
      this.reportsModuleV2.ReportDataType = typeof(DevExpress.Persistent.BaseImpl.ReportDataV2);
      this.reportsModuleV2.ReportStoreMode = DevExpress.ExpressApp.ReportsV2.ReportStoreModes.XML;
      // 
      // reportsAspNetModuleV2
      // 
      this.reportsAspNetModuleV2.ReportViewerType = DevExpress.ExpressApp.ReportsV2.Web.ReportViewerTypes.HTML5;
      // 
      // stateMachineModule
      // 
      this.stateMachineModule.StateMachineStorageType = typeof(DevExpress.ExpressApp.StateMachine.Xpo.XpoStateMachine);
      // 
      // validationModule
      // 
      this.validationModule.AllowValidationDetailsAccess = true;
      this.validationModule.IgnoreWarningAndInformationRules = false;
      // 
      // workflowModule
      // 
      this.workflowModule.RunningWorkflowInstanceInfoType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoRunningWorkflowInstanceInfo);
      this.workflowModule.StartWorkflowRequestType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoStartWorkflowRequest);
      this.workflowModule.UserActivityVersionType = typeof(DevExpress.ExpressApp.Workflow.Versioning.XpoUserActivityVersion);
      this.workflowModule.WorkflowControlCommandRequestType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoWorkflowInstanceControlCommandRequest);
      this.workflowModule.WorkflowDefinitionType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoWorkflowDefinition);
      this.workflowModule.WorkflowInstanceKeyType = typeof(DevExpress.Workflow.Xpo.XpoInstanceKey);
      this.workflowModule.WorkflowInstanceType = typeof(DevExpress.Workflow.Xpo.XpoWorkflowInstance);
      // 
      // AturableWiraAspNetApplication
      // 
      this.ApplicationName = "AturableWira";
      this.CheckCompatibilityType = DevExpress.ExpressApp.CheckCompatibilityType.DatabaseSchema;
      this.Modules.Add(this.module1);
      this.Modules.Add(this.module2);
      this.Modules.Add(this.auditTrailModule);
      this.Modules.Add(this.objectsModule);
      this.Modules.Add(this.chartModule);
      this.Modules.Add(this.cloneObjectModule);
      this.Modules.Add(this.conditionalAppearanceModule);
      this.Modules.Add(this.dashboardsModule);
      this.Modules.Add(this.validationModule);
      this.Modules.Add(this.kpiModule);
      this.Modules.Add(this.notificationsModule);
      this.Modules.Add(this.pivotChartModuleBase);
      this.Modules.Add(this.pivotGridModule);
      this.Modules.Add(this.reportsModuleV2);
      this.Modules.Add(this.schedulerModuleBase);
      this.Modules.Add(this.scriptRecorderModuleBase);
      this.Modules.Add(this.stateMachineModule);
      this.Modules.Add(this.treeListEditorsModuleBase);
      this.Modules.Add(this.viewVariantsModule);
      this.Modules.Add(this.workflowModule);
      this.Modules.Add(this.module3);
      this.Modules.Add(this.chartAspNetModule);
      this.Modules.Add(this.dashboardsAspNetModule);
      this.Modules.Add(this.fileAttachmentsAspNetModule);
      this.Modules.Add(this.htmlPropertyEditorAspNetModule);
      this.Modules.Add(this.mapsAspNetModule);
      this.Modules.Add(this.notificationsAspNetModule);
      this.Modules.Add(this.pivotChartAspNetModule);
      this.Modules.Add(this.pivotGridAspNetModule);
      this.Modules.Add(this.reportsAspNetModuleV2);
      this.Modules.Add(this.schedulerAspNetModule);
      this.Modules.Add(this.scriptRecorderAspNetModule);
      this.Modules.Add(this.treeListEditorsAspNetModule);
      this.Modules.Add(this.validationAspNetModule);
      this.Modules.Add(this.module4);
      this.Modules.Add(this.securityModule1);
      this.Security = this.securityStrategyComplex1;
      this.DatabaseVersionMismatch += new System.EventHandler<DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs>(this.AturableWiraAspNetApplication_DatabaseVersionMismatch);
      ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }
    }
}
